package javango.contrib.hibernate.tests;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

@Entity
@Table(name="test")
@IdClass(CompositeKeyTestBean.CompositeKeyTestBeanPk.class)
public class CompositeKeyTestBean {

	@Embeddable
	public static class CompositeKeyTestBeanPk implements Serializable {
		private String key;
		private Long key2;
		public String getKey() {
			return key;
		}
		public void setKey(String key) {
			this.key = key;
		}
		public Long getKey2() {
			return key2;
		}
		public void setKey2(Long key2) {
			this.key2 = key2;
		}
		@Override
		public boolean equals(Object obj) {
			if (obj instanceof CompositeKeyTestBeanPk) {
				CompositeKeyTestBeanPk other = (CompositeKeyTestBeanPk)obj;
				if (obj == null) return false;
				if (key == null && other.getKey() != null) return false;
				if (key == null && other.getKey2() != null) return false;
				
				return key.equals(other.getKey()) && key2.equals(other.getKey2());
			}
			return false;
		}
		@Override
		public int hashCode() {
			return key.hashCode() + key2.hashCode();
		}
		
		
	}
	
	@Id
	private String key;
	
	@Id
	private Long key2;
	
	@Column
	private String value;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public Long getKey2() {
		return key2;
	}

	public void setKey2(Long key2) {
		this.key2 = key2;
	}
}

